package com.zhonghui.scm.controller;

import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.core.page.TableDataInfo;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.response.BaseResult;
import com.zhonghui.scm.domain.ScmSalePlan;
import com.zhonghui.scm.service.IScmSalePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 销售计划Controller
 * 
 * @author zhonghui
 * @date 2022-05-26
 */
@Api(tags="供应链SCM-销售管理-销售计划")
@RestController
@RequestMapping("/scm/plan")
public class ScmSalePlanController extends BaseController
{
    @Autowired
    private IScmSalePlanService scmSalePlanService;

    /**
     * 查询销售计划列表
     */
    @ApiOperation("销售管理-销售计划列表")
    @GetMapping("/list")
    public TableDataInfo<List<ScmSalePlan>> getList(ScmSalePlan scmSalePlan)
    {
        startPage();
        List<ScmSalePlan> list = scmSalePlanService.getList(scmSalePlan);
        return getDataTable(list);
    }

    /**
     * 导出销售计划列表
     */
    @ApiOperation("导出销售管理-销售计划列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmSalePlan scmSalePlan)
    {
        List<ScmSalePlan> list = scmSalePlanService.getList(scmSalePlan);
        ExcelUtil<ScmSalePlan> util = new ExcelUtil<ScmSalePlan>(ScmSalePlan.class);
        util.exportExcel(response, list, "销售计划数据");
    }

    /**
     * 获取销售计划详细信息
     */
    @ApiOperation("销售管理-销售计划详细信息")
    @GetMapping(value = "/{id}")
    public BaseResult<ScmSalePlan> getById(@PathVariable("id") Long id)
    {
        return BaseResult.success(scmSalePlanService.getById(id));
    }

    /**
     * 新增销售计划
     */
    @ApiOperation("新增销售管理-销售计划")
    @PostMapping
    public BaseResult<Integer> add(@RequestBody ScmSalePlan scmSalePlan)
    {
        return BaseResult.success(scmSalePlanService.add(scmSalePlan));
    }

    /**
     * 修改销售计划
     */
    @ApiOperation("修改销售管理-销售计划")
    @PutMapping
    public BaseResult<Integer> edit(@RequestBody ScmSalePlan scmSalePlan)
    {
        return BaseResult.success(scmSalePlanService.edit(scmSalePlan));
    }

    /**
     * 删除销售计划
     */
    @ApiOperation("删除销售管理-销售计划")
	@DeleteMapping("/{ids}")
    public BaseResult<Integer> remove(@PathVariable Long[] ids)
    {
        return BaseResult.success(scmSalePlanService.del(ids));
    }
}
